package jMiiEditor.gui.miifilechooser;

import java.awt.Component;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JFileChooser;
import com.googlecode.cchlib.swing.filechooser.FileNameExtensionFilter;
import com.googlecode.cchlib.swing.filechooser.JFileChooserInitializer;

/**
 *
 * <CODE>
 *
 * </CODE>
 * @author CC
 */
public class MiiFileChooserDefaultImpl
    //extends XJFileChooser
        implements MiiFileChooser
{
    //private static final long serialVersionUID = 1L;
    public final static FileNameExtensionFilter miiFileFilter = new FileNameExtensionFilter( "Mii files", "mii", "mae" );
    private final JFileChooserInitializer jFileChooserInitializer;

    /**
     *
     */
    public MiiFileChooserDefaultImpl( final JFileChooserInitializer jFileChooserInitializer)
    {
        //this(null);
        this.jFileChooserInitializer = jFileChooserInitializer;
    }

//    /**
//     * @param defaultDir
//     */
//    public MiiFileChooserDefaultImpl( final File defaultDir )
//    {
//        super( defaultDir, miiFileFilter, EnumSet.of( XJFileChooser.Attrib.UseShellFolder ) );
//    }

    @Override
    public MiiFileObject showOpenDialogExt( Component parent )
            throws NullPointerException, FileNotFoundException, IOException
    {
        JFileChooser     jFileChooser     = this.jFileChooserInitializer.getJFileChooser();
        int             returnVal         = jFileChooser.showOpenDialog( parent );

        if(returnVal == JFileChooser.APPROVE_OPTION) {
            return new MiiFileObjectDefaultImpl( jFileChooser.getSelectedFile() );
            }

        return null; // no file
    }

    @Override
    public MiiFileObject showSaveDialogExt( Component parent )
            throws NullPointerException, FileNotFoundException, IOException
    {
        JFileChooser     jFileChooser     = this.jFileChooserInitializer.getJFileChooser();
        int             returnVal         = jFileChooser.showSaveDialog( parent );

        if(returnVal == JFileChooser.APPROVE_OPTION) {
            return new MiiFileObjectDefaultImpl( jFileChooser.getSelectedFile() );
            }

        return null; // no file
    }

}
